import sys, pygame
import random

from pygame.sprite import *
from pygame.sprite import *

from state_manager import *
from settings_manager import *

from menu_scene import MenuScene
from settings_scene import SettingsScene
from highscore_scene import HighscoreScene
from game_scene import GameScene

from button import *
from events import *

pygame.init()
pygame.display.set_caption("Crazy Boom")

screen = pygame.display.set_mode(SettingsManager.settings.resolution)

#Create scenes
menuScene = MenuScene(screen)
menuScene.create()

settingsScene = SettingsScene(screen)
settingsScene.create()

highscoreScene = HighscoreScene(screen)
highscoreScene.create()

gameScene = GameScene(screen)

def runGame():
	clock = pygame.time.Clock()

	while True:
		#FPS
		clock.tick(SettingsManager.settings.FPS)

		#Load events
		Events.pushEvents()

		#Main events
		handleMainEnvents()

		#Scenes Update
		menuScene.update()
		settingsScene.update()
		highscoreScene.update()
		gameScene.update()
		
		#Resolution changed
		if SettingsManager.resolutionChanged():
			screen = pygame.display.set_mode(SettingsManager.settings.resolution)
			menuScene.create()
			settingsScene.create()
			highscoreScene.create()
			
		

def exitGame():
    sys.exit()

def handleMainEnvents():
	for event in Events.events:
		if event.type == pygame.QUIT:
			exitGame()


#Run the game \:D/
runGame()
